package com.javasoft.controller.ZSW;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasoft.controller.ZSW.VO.FixedTypeVO;
import com.javasoft.entity.ZSW.DataDictionaryEntity;
import com.javasoft.service.ZSW.DataDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/datadic")
public class DataDictionaryController {

    @Autowired
    private DataDictionaryService dataDictionaryService;

    @PostMapping("/add")
    public  String add(@RequestBody DataDictionaryEntity dataDictionaryEntity){
        return dataDictionaryService.update(dataDictionaryEntity);
    }//完成增加或更改

    @PostMapping("/remove")
    public boolean remove(@RequestBody List<Integer> ids){
        return dataDictionaryService.delete(ids);
    }//完成删除

    @GetMapping("/check")
    public Page<DataDictionaryEntity> page(
            @RequestParam(defaultValue = "") String type,//查找类型
            @RequestParam(defaultValue = "1") Integer current,//页
            @RequestParam(defaultValue = "10") Integer size//行
    ){
        return dataDictionaryService.page(current,size,type);
    }//完成查询


    @PostMapping("insertfixedtype")
    public String insertFixedType(@RequestBody DataDictionaryEntity fixedType){
        Integer i= dataDictionaryService.add(fixedType);
        if(i==0){
            return "success";
        }
        else{
            return "fail";
        }
    }

    public IPage list(@RequestBody FixedTypeVO fixedTypeVO){
        DataDictionaryEntity type = new DataDictionaryEntity();
        type.setFixedtype(fixedTypeVO.getFixedtype());
        return dataDictionaryService.page(type,fixedTypeVO.getPage(),fixedTypeVO.getPageline());
    }
}
